<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('发放煤系统')" />
</head>
<body class="gray-bg">
<div class="container-div">

    <div class="row">
        <div class="col-sm-12 search-collapse">

            <div class="row">
            </div>
            <form id="formId">
                <input id="villageId" type="hidden" th:value="${user.deptId}">
                <div class="select-list">
                    <p>
                        <label th:text="'共计到本村煤：  '+${receiveNumber == null ? '0吨' : receiveNumber+'吨'}"></label>
                        <label style="margin-left:10px;" th:text="'发放：   '+${deliverNumber == null ? '0吨' : deliverNumber+'吨'}"></label>
                    </p>
                    <ul>
                        <li>
                            <label>查找：</label>
                            <input type="text" name="keyword" placeholder="输入姓名、身份证号、手机号"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-bordered">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var prefix = ctx + "jjm/clientUserorder";

    $(function() {
        var options = {
            url: prefix + "/list?villageId="+[[${user.deptId}]],
            updateUrl: prefix + "/edit/{id}?type=2",
            exportUrl: prefix + "/export",
            confirmUrl: prefix + "/confirm",
            modalName: "村民购煤记录",
            showSearch: false,
            showRefresh: false,
            showToggle: false,
            showColumns: false,
            sortName: "id",
            sortOrder: "desc",
            columns: [
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    title: "编号",
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'clientUser.masterName',
                    title: '户主姓名'
                },
                {
                    field: 'clientUser.masterIdentityCardNumber',
                    title: '身份证号'
                },
                {
                    field: 'amount',
                    title: '购煤数量（吨）'
                },
                {
                    field: 'money',
                    title: '购煤款'
                },
                {
                    field: 'createTime',
                    title: '购煤时间',
                    formatter: function(value, row, index) {
                        return new Date(value).format("yyyy-MM-dd");
                    }
                },
                {
                    field: 'takeinTime',
                    title: '收到煤时间',
                    formatter: function(value, row, index) {
                        return value ? new Date(value).format("yyyy-MM-dd") : "";
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.status){
                            //已发货，确认收煤
                            if(row.status == 1){
                                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="confirm(\'' + row.id + '\')">确认收煤</a> ');
                            }else if(row.status == 2 && row.takeinTime){
                                actions.push('<span class="btn btn-default btn-xs">'+new Date(row.takeinTime).format("yyyy-MM-dd")+"收到煤</span>&nbsp;");
                            }
                        }
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>错误信息修改</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function purchase() {
        $.modal.openTab("集中购煤",prefix+"/purchase");
    }
    function purchaseRecord() {
        $.modal.openTab("购煤记录","/jjm/order?villageId="+$("#villageId").val());
    }
    function confirm(id) {
        table.set();
        $.modal.confirm("您确认该居民已收到煤吗？", function() {
            var url = $.common.isEmpty(id) ? table.options.confirmUrl : table.options.confirmUrl.replace("{id}", id);
            var data = { "id": id };
            $.operate.submit(url, "post", "json", data);
        });

    }
</script>
</body>
</html>